package com.gitee.zw.rule.${ruleDomain.code};
dialect  "mvel"

import java.util.*;
import com.gitee.zw.rule.utils.*;

global org.slf4j.Logger log;

<#-- 生成类代码 -->
declare ${ruleDomain.factClass}
<#list dimensionTypes as k,v>
    ${k} :${v}
</#list>
end
<#-- 规则定义 -->
<#list ruleDomain.rules as rule>
/* ${rule.memo} */
rule "rule-${ruleDomain.code}-${rule.code}"
    when
        $c: ${ruleDomain.factClass}()
    then
        log.debug("start to process: {}", $c);
    <#assign i1 = 0 />
    <#list rule.branches as branch>
        <#if i1 gt 0 && branch.isGrouped> else </#if>if (true<#list branch.dimensions as dimension> && (${ExpressionUtils.toExpression(dimension.operator, "$c." + dimension.code, dimension.value)})</#list>) {
        <#list branch.targets as target>
            ${ExpressionUtils.toExpression(target.operator, "$c." + target.code, target.value)};
        </#list>
            log.debug("${branch.memo}");
        <#if !branch.isContinue>
            return;
        </#if>
        }
        <#assign i1 = i1 + 1 />
    </#list>
    end
</#list>
